package com.ztest.multithreaddemo1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

@Component
@Slf4j
public class TaskStatusStore {
    private final ConcurrentHashMap<Integer, String> taskStatuses = new ConcurrentHashMap<>();
    private final AtomicInteger taskIdGenerator = new AtomicInteger(0);

    public int generateTaskId() {
        return taskIdGenerator.incrementAndGet();
    }

    public void setTaskStatus(int taskId, String status) {
        taskStatuses.put(taskId, status);
    }

    public String getTaskStatus(int taskId) {
        return taskStatuses.getOrDefault(taskId, "NOT_FOUND");
    }
}
